package com.ziven.common.widget.value;

import android.util.TypedValue;
import android.view.View;

import androidx.annotation.DimenRes;
import androidx.annotation.NonNull;

import com.ziven.common.widget.WidgetUtils;
import com.ziven.easygo.util.ViewHelper;

/**
 * @author Ziven
 */
public final class TextSize extends Value {

    public static TextSize dimenId(@DimenRes int dimenId) {
        return new TextSize().accept(my -> my.resId = dimenId);
    }

    public static TextSize size(float size) {
        return new TextSize().accept(my -> my.value = size);
    }

    public static TextSize size(@NonNull String sp) {
        return size(WidgetUtils.dimen(sp));
    }

    private TextSize() {}

    @Override
    protected void takeEffect(@NonNull ViewHelper<? extends View> helper) {
        if(resId == 0) {
            value(Float.class, value -> helper.setTextSize(TypedValue.COMPLEX_UNIT_PX, value));
        } else {
            helper.setTextSizeId(resId);
        }
    }
}
